package com.yy.service;

import com.yy.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;

import com.yy.pojo.File;
import com.yy.mapper.FileMapper;
import com.yy.service.FileService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

import java.util.Date;
import java.util.List;


/**
 * @Author: yy
 * @Date 2021/11/21 12:02
 */
@Component
@Service
public class FileService {
    @Autowired
    @Resource
    private FileMapper fileMapper;

    public List<File> getFilesByUserId(String uid) {
        return fileMapper.getFilesByUserId(uid);
    }

    public List<File> getFileList() {
        return fileMapper.getFileList();
    }


    public void SaveFile(File file) {
        //进行三目运算判断，文件是否是图片
        String isImg = file.getFileType().startsWith("image")?"是":"否";
        System.out.println(isImg);
        file.setIsImg(isImg);
        file.setDownCounts(0);
        file.setUploadTime(new Date());
        fileMapper.SaveFile(file);
    }


    public File getFilesById(String uid) {
        return fileMapper.getFilesById(uid);
    }


    public void update(File file) {
        fileMapper.update(file);
    }


    public void delete(String uid) {
        fileMapper.delete(uid);
    }
}
